/*
 *  This file is part of Fuzzy Ontology Framework Project.
 *
 *   Fuzzy Ontology Framework Project is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   Fuzzy Ontology Framework Project is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   If you want a copy of the GNU General Public License
 *   write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package fuzzyOntologyFramework;

import java.util.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;

public class SubClassQuicksort {

	private int partition(List list, int begin, int end) {
		
		OntClass ontClass = (OntClass) ((RDFNode)list.get(begin)).as(OntClass.class), temp; 
		int i = begin + 1, j = end;
		while (i <= j) {
			if ( ( (OntClass)((RDFNode)list.get(i)).as(OntClass.class) ).hasSubClass(ontClass) ) 
				++i;
			else if ( ontClass.hasSubClass( (OntClass)((RDFNode)list.get(j)).as(OntClass.class) ) )
					--j;
			else {
				temp  = (OntClass) ((RDFNode)list.get(i)).as(OntClass.class);
				list.set(i, list.get(j));
				list.set(j, temp);
				++i;
				--j;
			}
		}
		temp = (OntClass) ((RDFNode)list.get(begin)).as(OntClass.class);
		list.set(begin, list.get(j));
		list.set(j, temp);
		return j;
	}
	
	public void quicksort(List list, int begin, int end) {
		
		int j;
		if (begin < end) {
			j = partition(list, begin, end);
			quicksort(list, begin, j-1);
			quicksort(list, j+1, end);
		}
		
	}
	
}
